import {Injectable} from '@angular/core';
import {SysCodeCategorySearchForm} from '../entity/sys-code-category-search-form';
import {SysCodeCategory} from '../entity/sys-code-category';
import {BaseTreeService} from '@sb/base/core/service/base-tree.service';
import {SysCodeCategoryTreeNode} from '../entity/sys-code-category-tree-node';
import {Observable} from 'rxjs';
import {baseHandleError, ReturnForm} from '@sb/base';
import {catchError} from 'rxjs/operators';

/**
 * 机构服务
 */
@Injectable({
    providedIn: 'root'
})
export class SysCodeCategoryService extends BaseTreeService<SysCodeCategory, SysCodeCategorySearchForm, SysCodeCategoryTreeNode> {

    basePath = 'sys/code/module';


    /**
     * 获取路径
     * @param moduleCode 节点标识
     */
    getTreeNodeCodePath(moduleCode?: string): Observable<ReturnForm<string[]>> {
        return this._http.post<ReturnForm<string[]>>(`${this.url}/getTreeNodeCodePath`, {
            moduleCode: moduleCode
        }).pipe(
            catchError(baseHandleError<ReturnForm<string[]>>('getTreeNodeCodePath'))
        );
    }
}
